package com.yun.algorithmproblem.leetcode;

import java.util.HashMap;

public class Leetcode2364 {


	public long countBadPairs(int[] nums) {
		HashMap<Integer, Integer> map = new HashMap<>();
		int n = nums.length;
		int size=0;
		long ans=0;
		for (int i = 0; i < nums.length; i++) {
			int d = nums[i] - i;
			Integer same = map.getOrDefault(d, 0);
			ans+=size-same;
			map.put(d,same+1);
			size++;
		}
		return ans;
	}
}
